<template>
  <el-upload
    drag
    :action="uploadUrl"
    multiple
    :headers="{
        token
    }"
    name="img"
    :data="data"
    :on-success="onSuccess"
    :on-error="onError"
  >
    <el-icon class="el-icon--upload"><upload-filled /></el-icon>
    <div class="el-upload__text">
      Drop file here or <em>click to upload</em>
    </div>
    <template #tip>
      <div class="el-upload__tip">
        jpg/png files with a size less than 500kb
      </div>
    </template>
  </el-upload>
</template>
  
  <script setup>
  import {uploadUrl} from '@/api/image.js'
  import {getToken } from '@/composables/auth.js'
  import {Notify} from "@/composables/util.js"
  const token=getToken()
  const emit =defineEmits(['success'])
  const onSuccess=(response, uploadFile, uploadFiles)=>{
    console.log(response);
emit('success',{response, uploadFile, uploadFiles})
  }
  const onError=(error, uploadFile, uploadFiles)=>{
    let msg =JSON.parse(error.message)||'上传失败'
    Notify(msg)
  }
 
defineProps({
    data:Object,
})
</script>